/**
 * Created by zzc on 2017/11/23
 */

'use strict'

import React, {Component} from 'react';

import {
    View,
    Text,
    Image,
    StyleSheet
} from 'react-native';

import StringUtil from "../../../base/util/StringUtil"

export default class HouseDetailBasicInfo extends Component {

    constructor(props) {
        super(props)
        this.state = {
            response: "",
        }
    }

    componentWillReceiveProps = (nextProps) => {
        this.setState({
            response: nextProps.item
        });
    }

    render() {
        const info = this.state.response;
        return (

            <View style={styles.contain}>

                <Text style={{color:"black",fontSize:13}}>基本信息</Text>
                <View style={{backgroundColor: "#F7F8FA", marginTop: 5, height: 1}}></View>

                <View style={{flexDirection: "row"}}>

                    <View style={styles.childContent}>

                        <Text style={styles.titleLeft}>户型</Text>
                        <Text style={styles.contentRight}>{this._getHuxing()}</Text>
                    </View>
                    <View style={styles.childContent}>
                        <Text style={styles.titleLeft}>装修</Text>
                        <Text style={styles.contentRight}>{this._filterNull(info.fitmentType)}</Text>
                    </View>
                </View>

                <View style={{flexDirection: "row"}}>

                    <View style={styles.childContent}>

                        <Text style={styles.titleLeft}>面积</Text>
                        <Text style={styles.contentRight}>{info.size+"㎡"}</Text>
                    </View>
                    <View style={styles.childContent}>
                        <Text style={styles.titleLeft}>朝向</Text>
                        <Text style={styles.contentRight}>{this._filterNull(info.direction)}</Text>
                    </View>
                </View>

                <View style={{flexDirection: "row"}}>

                    <View style={styles.childContent}>

                        <Text style={styles.titleLeft}>楼层</Text>
                        <Text style={styles.contentRight}>{info.floor+"/"+info.totalFloor+"层"}</Text>
                    </View>
                    <View style={styles.childContent}>
                        <Text style={styles.titleLeft}>方式</Text>
                        <Text style={styles.contentRight}>{info.rentType=="SHARE"?"合租":"整租"}</Text>
                    </View>
                </View>

            </View>
        );
    }

    _getHuxing(){
        let huxing = "";
        let info = this.state.response;
        if(info.rentType == "SHARE"){
            huxing = info.rooms+"室"+info.hall+"厅"+info.toilet+"卫"
        }else{
            huxing = info.rooms+"室"+info.totalHall+"厅"+info.totalToilet+"卫"
        }
        return huxing;
    }

    _filterNull(data){
        return StringUtil.isEmpty(data)?" ":data;
    }
}

const styles = StyleSheet.create({
    contain: {
        backgroundColor: 'white',
        flexDirection: "column",
        paddingTop: 10,
        paddingLeft: 10,
        paddingBottom: 10,
        marginTop:10
    },
    childContent:{
        flexDirection: "row",
        flex:1,
        justifyContent:"flex-start",
        marginTop:10
    },
    titleLeft:{
        fontSize:16,
        color:"#8f8e94"
    },
    contentRight:{
        fontSize:16,
        color:"black",
        marginLeft:5
    }
});